class Solution {
public:
    bool fun(int x) {
        if (x == 1)return 0;
        for (int i = 2; i * i <= x; i++) {
            if (x % i == 0)return 0;
        }
        return 1;
    }
    int maximumPrimeDifference(vector<int>& nums) {
        int n = nums.size();
        int ans = 0;
        int l = 0;
        int r = 0;
        for (int i = 0; i < n; i++) {
            if (fun(nums[i])) {
                l = i;
                break;
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            if (fun(nums[i])) {
                r = i;
                break;
            }
        }
        return r - l;
    }
};